﻿// Decompiled with JetBrains decompiler
// Type: MCM.LightInject.LightInjectServiceContainer
// Assembly: MCMv5, Version=5.10.2.0, Culture=neutral, PublicKeyToken=null
// MVID: 7AB326B9-B2B4-41C2-9177-68E944071101
// Assembly location: D:\steam\steamapps\workshop\content\261550\2859238197\bin\Win64_Shipping_Client\MCMv5.dll

using BUTR.DependencyInjection;
using BUTR.DependencyInjection.Logger;
using System;
using System.Linq;

#nullable enable
namespace MCM.LightInject
{
  internal class LightInjectServiceContainer : IGenericServiceContainer
  {
    private readonly IServiceContainer _serviceContainer;

    public LightInjectServiceContainer(IServiceContainer serviceContainer)
    {
      this._serviceContainer = serviceContainer;
    }

    public IGenericServiceContainer RegisterSingleton<TService>() where TService : class
    {
      this._serviceContainer.RegisterSingleton<TService>();
      return (IGenericServiceContainer) this;
    }

    public IGenericServiceContainer RegisterSingleton<TService>(
      Func<IGenericServiceFactory, TService> factory)
      where TService : class
    {
      this._serviceContainer.RegisterSingleton<TService>((Func<IServiceFactory, TService>) (lightInjectFactory => factory((IGenericServiceFactory) new LightInjectGenericServiceFactory(lightInjectFactory))));
      return (IGenericServiceContainer) this;
    }

    public IGenericServiceContainer RegisterSingleton<TService, TImplementation>()
      where TService : class
      where TImplementation : class, TService
    {
      this._serviceContainer.RegisterSingleton<TService, TImplementation>();
      return (IGenericServiceContainer) this;
    }

    public IGenericServiceContainer RegisterSingleton<TService, TImplementation>(
      Func<IGenericServiceFactory, TImplementation> factory)
      where TService : class
      where TImplementation : class, TService
    {
      this._serviceContainer.RegisterSingleton<TService>((Func<IServiceFactory, TService>) (lightInjectFactory => (TService) factory((IGenericServiceFactory) new LightInjectGenericServiceFactory(lightInjectFactory))));
      return (IGenericServiceContainer) this;
    }

    public IGenericServiceContainer RegisterSingleton(Type serviceType, Type implementationType)
    {
      this._serviceContainer.RegisterSingleton(serviceType, implementationType);
      return (IGenericServiceContainer) this;
    }

    public IGenericServiceContainer RegisterSingleton(Type serviceType, Func<object> factory)
    {
      this._serviceContainer.RegisterSingleton(serviceType, (Func<IServiceFactory, object>) (_ => factory()));
      return (IGenericServiceContainer) this;
    }

    public IGenericServiceContainer RegisterScoped<TService>() where TService : class
    {
      this._serviceContainer.RegisterScoped<TService>();
      return (IGenericServiceContainer) this;
    }

    public IGenericServiceContainer RegisterScoped<TService>(
      Func<IGenericServiceFactory, TService> factory)
      where TService : class
    {
      this._serviceContainer.RegisterScoped<TService>((Func<IServiceFactory, TService>) (lightInjectFactory => factory((IGenericServiceFactory) new LightInjectGenericServiceFactory(lightInjectFactory))));
      return (IGenericServiceContainer) this;
    }

    public IGenericServiceContainer RegisterScoped<TService, TImplementation>()
      where TService : class
      where TImplementation : class, TService
    {
      this._serviceContainer.RegisterScoped<TService, TImplementation>();
      return (IGenericServiceContainer) this;
    }

    public IGenericServiceContainer RegisterScoped<TService, TImplementation>(
      Func<IGenericServiceFactory, TImplementation> factory)
      where TService : class
      where TImplementation : class, TService
    {
      this._serviceContainer.RegisterScoped<TService>((Func<IServiceFactory, TService>) (lightInjectFactory => (TService) factory((IGenericServiceFactory) new LightInjectGenericServiceFactory(lightInjectFactory))));
      return (IGenericServiceContainer) this;
    }

    public IGenericServiceContainer RegisterScoped(Type serviceType, Type implementationType)
    {
      this._serviceContainer.RegisterScoped(serviceType, implementationType);
      return (IGenericServiceContainer) this;
    }

    public IGenericServiceContainer RegisterScoped(Type serviceType, Func<object> factory)
    {
      this._serviceContainer.RegisterScoped(serviceType, (Func<IServiceFactory, object>) (_ => factory()));
      return (IGenericServiceContainer) this;
    }

    public IGenericServiceContainer RegisterTransient<TService>() where TService : class
    {
      this._serviceContainer.RegisterTransient<TService>();
      return (IGenericServiceContainer) this;
    }

    public IGenericServiceContainer RegisterTransient<TService>(
      Func<IGenericServiceFactory, TService> factory)
      where TService : class
    {
      this._serviceContainer.RegisterTransient<TService>((Func<IServiceFactory, TService>) (lightInjectFactory => factory((IGenericServiceFactory) new LightInjectGenericServiceFactory(lightInjectFactory))));
      return (IGenericServiceContainer) this;
    }

    public IGenericServiceContainer RegisterTransient<TService, TImplementation>()
      where TService : class
      where TImplementation : class, TService
    {
      this._serviceContainer.RegisterTransient<TService, TImplementation>();
      return (IGenericServiceContainer) this;
    }

    public IGenericServiceContainer RegisterTransient<TService, TImplementation>(
      Func<IGenericServiceFactory, TImplementation> factory)
      where TService : class
      where TImplementation : class, TService
    {
      this._serviceContainer.RegisterTransient<TService>((Func<IServiceFactory, TService>) (lightInjectFactory => (TService) factory((IGenericServiceFactory) new LightInjectGenericServiceFactory(lightInjectFactory))));
      return (IGenericServiceContainer) this;
    }

    public IGenericServiceContainer RegisterTransient(Type serviceType, Type implementationType)
    {
      this._serviceContainer.RegisterTransient(serviceType, implementationType);
      return (IGenericServiceContainer) this;
    }

    public IGenericServiceContainer RegisterTransient(Type serviceType, Func<object> factory)
    {
      this._serviceContainer.RegisterTransient(serviceType, (Func<IServiceFactory, object>) (_ => factory()));
      return (IGenericServiceContainer) this;
    }

    public IGenericServiceProvider Build()
    {
      if (this._serviceContainer.AvailableServices.All<ServiceRegistration>((Func<ServiceRegistration, bool>) (s => s.ServiceType != typeof (IBUTRLogger))))
        this._serviceContainer.RegisterTransient<IBUTRLogger, DefaultBUTRLogger>();
      if (this._serviceContainer.AvailableServices.All<ServiceRegistration>((Func<ServiceRegistration, bool>) (s => s.ServiceType != typeof (IBUTRLogger<>))))
        this._serviceContainer.RegisterTransient(typeof (IBUTRLogger<>), typeof (DefaultBUTRLogger<>));
      this._serviceContainer.Compile();
      return (IGenericServiceProvider) new LightInjectGenericServiceProvider(this._serviceContainer);
    }
  }
}
